package com.qf.ssm.controller;

import com.qf.ssm.entity.PropertyManage;
import com.qf.ssm.service.PropertyManageService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/PropertyManage")
public class PropertyManageController {
    @Resource
    PropertyManageService propertyManageService;

    /**
     * 根据类型和属性id查询属性--------------展示
     * 测试通过，测试内容：
     *{
     *   "pmType": "非关键属性",
     *   "as": "中年休闲"
     * }
     * @param pmType
     * @param as
     * @return
     */
    @GetMapping("/asQuery")
    private ResponseResult<List<PropertyManage>> asQuery(String pmType, String as) {
        return ResponseResult.success(propertyManageService.selectAs(pmType, as));
    }

    /**
     * 根据类型和属性名查询属性------------展示
     *测试通过，测试内容：
     *{
     *   "pmType": "非关键属性",
     *   "pmName": "中年人"
     * }
     * @param pmType
     * @param pmName
     * @return
     */
    @GetMapping("/nameQuery")
    private ResponseResult<List<PropertyManage>> nameQuery(String pmType, String pmName) {
        return ResponseResult.success(propertyManageService.selectName(pmType, pmName));
    }

    /**
     * 根据类型和组id查询属性---------------展示
     *测试通过，测试内容：
     * {
     *   "pmType": "非关键属性",
     *   "pgId": 2
     * }
     * @param pmType
     * @param pgId
     * @return
     */
    @GetMapping("/groupQuery")
    private ResponseResult<List<PropertyManage>> groupQuery(String pmType, int pgId) {
        return ResponseResult.success(propertyManageService.selectGroup(pmType, pgId));
    }

    /**
     * 编辑属性-------------------展示
     *测试通过，测试内容：
     * {
     *   "pmId": 20,
     *   "pmName": "demoData",
     *   "pgId": "demoData",
     *   "pmAs": "demoData",
     *   "pmType": "demoData"
     * }
     * 加RequestBody error，不加success
     * @param propertyManage
     * @return
     */
    @PutMapping("/editProperty")
    private ResponseResult<Integer> editProperty(PropertyManage propertyManage) {
        return ResponseResult.success(propertyManageService.update(propertyManage));
    }

    /**
     * 当前页面默认展示的属性条数---------------展示
     *测试通过，测试内容：
     * {空值}
     * @return
     */
    @GetMapping("/queryDefaultDisplay")
    private ResponseResult<List<PropertyManage>> queryDefaultDisplay() {
        return ResponseResult.success(propertyManageService.selectDefaultDisplay());
    }

    /**
     * 新建属性----------------------展示
     *测试通过，测试内容：
     * {
     *   "pmName": "Data",
     *   "pgId": "oData",
     *   "pmAs": "oData",
     *   "pmType": "demoData",
     *   "status": 1
     * }
     * @param propertyManage
     * @return
     */
    @PostMapping("/newProperty")
    private ResponseResult<Integer> newProperty(@RequestBody PropertyManage propertyManage) {
        return ResponseResult.success(propertyManageService.insert(propertyManage));
    }

    /**
     * 删除属性(伪删除)-----------------展示
     *测试通过，测试内容：
     * {
     *   "pmId": 9
     * }
     * @return
     */
    @PutMapping("/deleteProperty")
    private ResponseResult<Integer> deleteProperty(Integer pmId) {
        return ResponseResult.success(propertyManageService.delete(pmId));
    }

    /**
     * 禁用属性----------------------展示
     *测试通过，测试内容：
     * {
     *   "pmId": 9
     * }
     */
    @PutMapping("/disableProperty")
    private ResponseResult<Integer> disableProperty(Integer pmId) {
        return ResponseResult.success(propertyManageService.disable(pmId));
    }

    /**
     * 启用属性-----------------------展示
     * 测试通过，测试内容：
     *{
     *   "pmId": 9
     * }
     *
     */
    @PutMapping("/enableProperty")
    private ResponseResult<Integer> enableProperty(Integer pmId) {
        return ResponseResult.success(propertyManageService.enable(pmId));
    }

    /**
     * 批量删除--------------------不展示
     *
     */
    @PutMapping("/batchDeleteProperty")
    private ResponseResult<Integer> batchDeleteProperty(int[] pmIds) {
        return ResponseResult.success(propertyManageService.batchDelete(pmIds));
    }

    /**
     * 一对一查询-----------------不展示
     */
    @GetMapping("/queryPropertyAndGroup")
    private ResponseResult<PropertyManage> queryPropertyAndGroup(int pmId) {
        return ResponseResult.success(propertyManageService.selectPropertyAndGroup(pmId));
    }

    /**
     * 批量插入-----------------不展示
     *
     * @param propertyManages
     * @return
     */

    @PostMapping("/batchNewProperty")
    private ResponseResult<Integer> batchNewProperty(@RequestBody List<PropertyManage> propertyManages) {
        return ResponseResult.success(propertyManageService.batchInsert(propertyManages));
    }

    /**
     * 通过list批量删除属性------------不展示
     *
     *
     */

    @PutMapping("/batchDeletePropertyList")
    private ResponseResult<Integer> batchDeletePropertyList(@RequestBody List<Integer> pmIds){
        return ResponseResult.success(propertyManageService.batchDeleteList(pmIds));
    }
    /**
     * 使用注解list批量插入-------------不展示
     *
     *
     */
    @PostMapping("/batchNewPropertyList")
    private ResponseResult<Integer> batchNewPropertyList(@RequestBody List<PropertyManage> propertyManages){
        return ResponseResult.success(propertyManageService.batchInsertList(propertyManages));
    }
}
